#########################
#   Author : Leon yu    #
#   Date : 2025/06/03   #
#   Id : SM2772         #
#########################
from apiRespsAnalyze import *

# 数据解析
def businessOverviewResult(startTime, endTime):
    result = dict()
    # 营业概览 - 营业收入
    def operatingIncome(startTime:int=startTime, endTime:int=endTime, businessType="TURNOVER"):
        operatingIncomeResults = analyzeQueryBusinessTrendReport(businessType=businessType, startTime=startTime, endTime=endTime)
        operatingIncomeResults2Day = list()
        for i in operatingIncomeResults:
            tempDict = {}
            for key, value in i.items():
                tempDict['TURNOVER'] = value['amount']
                operatingIncomeResults2Day.append(tempDict)
        return operatingIncomeResults2Day[0]

    # 营业概览 - 订单数
    def orderCount(startTime:int=startTime, endTime:int=endTime, businessType="ORDERNUMS"):
        operatingIncomeResults = analyzeQueryBusinessTrendReport(businessType=businessType, startTime=startTime, endTime=endTime)
        operatingIncomeResults2Day = list()
        for i in operatingIncomeResults:
            tempDict = {}
            for key, value in i.items():
                tempDict['ORDERNUMS'] = value
                operatingIncomeResults2Day.append(tempDict)
        return operatingIncomeResults2Day[0]

    # 营业概览 - 商品数量
    def skuCount(startTime:int=startTime, endTime:int=endTime, businessType="ITEMNUMS"):
        operatingIncomeResults = analyzeQueryBusinessTrendReport(businessType=businessType, startTime=startTime, endTime=endTime)
        operatingIncomeResults2Day = list()
        for i in operatingIncomeResults:
            tempDict = {}
            for key, value in i.items():
                tempDict['ITEMNUMS'] = value
                operatingIncomeResults2Day.append(tempDict)
        return operatingIncomeResults2Day[0]

    def grossProfit(startTime:int=startTime, endTime:int=endTime, businessType="GROSS"):
        operatingIncomeResults = analyzeQueryBusinessTrendReport(businessType=businessType, startTime=startTime, endTime=endTime)
        operatingIncomeResults2Day = list()
        for i in operatingIncomeResults:
            tempDict = {}
            for key, value in i.items():
                tempDict['GROSS'] = value['amount']
                operatingIncomeResults2Day.append(tempDict)
        return operatingIncomeResults2Day[0]
    resultTmp = list()
    resultTmp.append(operatingIncome())
    resultTmp.append(orderCount())
    resultTmp.append(skuCount())
    resultTmp.append(grossProfit())
    result[timestamp2Data(startTime).split()[0]] = resultTmp
    return result

# print(businessOverviewResult(startTime=1717520400000, endTime=1717606799000))